/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 17655
 * Date: 2025-07-09
 * Time: 18:24
 */
public class test3 {
    int ans;
    public int diameterOfBinaryTree(TreeNode root) {
        // 返回结果
        get(root);
        return ans;
    }


    public int get(TreeNode root){
        if(root==null){
            return -1;
        }
        int left = get(root.left)+1;
        int right = get(root.right)+1;
        ans = Math.max(ans,right+left);
        return Math.max(left,right);
    }

    class TreeNode{
        TreeNode left;
        TreeNode right;
    }
}
